﻿using System;
using System.Windows.Forms;

namespace FootSteps.Domain.Loggers.Keyboard
{
    public class KeyArgs
    {
        public Keys Keys { get; private set; }
        public bool Shift { get; private set; }
        public bool Capital { get; private set; }
        public bool Control { get; private set; }
        public DateTime Time { get; private set; }

        public KeyArgs(Keys keys, DateTime time)
        {
            Keys = keys;
            Shift = System.Windows.Forms.Control.ModifierKeys == Keys.Shift;
            Capital = System.Windows.Forms.Control.IsKeyLocked(Keys.CapsLock);
            Control = System.Windows.Forms.Control.ModifierKeys == Keys.Control;
            Time = time;
        }

        public override string ToString()
        {
            var isChar = Keys >= Keys.A && Keys <= Keys.Z;
            var isNumber = Keys >= Keys.D0 && Keys <= Keys.D9;

            var s = (isChar && !(Shift ^ Capital)) ? Keys.ToString().ToLower() : Keys.ToString();

            if (isNumber) s = s.Substring(1, 1);

            if (Shift) s += " + Shift";
            if (Control) s += " + Control";
            if (Capital) s += " + Capslock";

            return s;
        }
    }
}